package com.jwater.core.manager.common.service;

import java.util.List;

import com.jwater.core.manager.common.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jwater.core.annotation.JwaterRpcService;
import com.jwater.core.manager.master.MasterFactory;

/**
 * @description: rpc实现类
 * @author: jnner
 * @createDate: 2021/2/5
 * @version: 1.0
 */
@JwaterRpcService(superClazz = JwaterService.class)
public class JwaterServiceImpl implements JwaterService {
    protected static Logger logger = LoggerFactory.getLogger(JwaterServiceImpl.class);

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param workerName
     * @return
     */
    @Override
    public WorkerInfo getWorkerInfo(String regionName, String deployName, String groupName, String workerName) {
        return MasterFactory.getMasterContext().getWorkerInfo(regionName, deployName, groupName, workerName);
    }

    /**
     * @param regionName
     * @return
     */
    @Override
    public List<WorkerInfo> getWorkerList(String regionName) {
        return MasterFactory.getMasterContext().getWorkerList(regionName);
    }

    /**
     * @param regionName
     * @param deployName
     * @return
     */
    @Override
    public List<String> getWorkerConfList(String regionName, String deployName) {
        return MasterFactory.getMasterContext().getWorkerConfList(regionName, deployName);
    }

    /**
     * @param regionName
     * @param deployName
     * @return
     */
    @Override
    public List<String> getWorkerConfRoot(String regionName, String deployName) {
        return MasterFactory.getMasterContext().getWorkerConfRoot(regionName, deployName);
    }

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param workerName
     * @param index
     */
    @Override
    public void startWorker(String regionName, String deployName, String groupName, String workerName, int index) {
        MasterFactory.getMasterContext().startWorker(regionName, deployName, groupName, workerName, index);
    }

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param workerName
     * @param index
     */
    @Override
    public void stopWorker(String regionName, String deployName, String groupName, String workerName, int index,
                           boolean isForce) {
        MasterFactory.getMasterContext().stopWorker(regionName, deployName, groupName, workerName, index, isForce);
    }

    /**
     * @param regionName
     * @return
     */
    @Override
    public List<JobInfo> getJobList(String regionName) {
        return MasterFactory.getMasterContext().getJobList(regionName);
    }

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param jobName
     */
    @Override
    public void startJob(String regionName, String deployName, String groupName, String jobName) {
        MasterFactory.getMasterContext().startJob(regionName, deployName, groupName, jobName);
    }

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param jobName
     */
    @Override
    public void stopJob(String regionName, String deployName, String groupName, String jobName) {
        MasterFactory.getMasterContext().stopJob(regionName, deployName, groupName, jobName);
    }

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param jobName
     * @param time
     */
    @Override
    public void runJob(String regionName, String deployName, String groupName, String jobName, long time) {
        MasterFactory.getMasterContext().runJob(regionName, deployName, groupName, jobName, time, true);
    }

    /**
     * @param regionName
     * @param deployName
     * @param groupName
     * @param jobName
     */
    @Override
    public void killJob(String regionName, String deployName, String groupName, String jobName) {
        MasterFactory.getMasterContext().killJob(regionName, deployName, groupName, jobName);
    }

    /**
     * @param regionName
     */
    @Override
    public void loadConf(String regionName) {
        MasterFactory.getMasterContext().loadConf(regionName);
    }

    @Override
    public List<SystemInfo> getAllSystemInfo() {
        return MasterFactory.getMasterContext().getAllSystemInfo();
    }

    @Override
    public void removeAlarmInfo(String type) {
        MasterFactory.getMasterContext().removeAlarmInfo(type);
    }

    @Override
    public List<AlarmInfo> getAllAlarmInfo() {
        return MasterFactory.getMasterContext().getAllAlarmInfo();
    }

    @Override
    public List<PackageInfo> getPackageInfo() {
        return MasterFactory.getMasterContext().getPackageInfo();
    }

    @Override
    public List<GatewayProxyInfo> getGatewayProxyInfo(String gatewayGroupName, String gatewayWorkerName) {
        return MasterFactory.getMasterContext().getGatewayProxyInfo(gatewayGroupName, gatewayWorkerName);
    }

    @Override
    public List<GatewayProxyInfo> getGatewayProxyInfo(String gatewayGroupName, String gatewayWorkerName, int gatewayIndex,
                                                      String gatewayRegionName, String gatewayDeployName) {
        return MasterFactory.getMasterContext().getGatewayProxyInfo(gatewayGroupName, gatewayWorkerName, gatewayIndex
                , gatewayRegionName, gatewayDeployName);
    }
}
